#include "FiveWin.ch"

#define BS_AUTORADIOBUTTON            9
#define BM_SETCHECK         (WM_USER+1)

//----------------------------------------------------------------------------//

CLASS TRadio FROM TControl

   DATA   lChecked             // to init correctly its state
   DATA   oRadMenu
   DATA   nPos

   METHOD New( nRow, nCol, cCaption, lGroup, lChecked, nPos, oWnd, oRadMenu,;
               nHelpId ) CONSTRUCTOR
   METHOD Redefine( nID, lChecked, nPos, oDlg, oRadMenu, ;
               nHelpID ) CONSTRUCTOR
   METHOD Click()      BLOCK { | Self | ::oRadMenu:nOption := ::nPos }
   METHOD cToChar()    BLOCK { | Self | Super:cToChar( "BUTTON" ) }
   METHOD Init( hDlg ) BLOCK ;
              { | Self, hDlg | Super:Init( hDlg ), ::SetCheck( ::lChecked ) }
   METHOD SetCheck( lOnOff ) BLOCK ;
            { | Self, lOnOff | ::SendMsg( BM_SETCHECK, If( lOnOff, 1, 0 ) ) }

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nRow, nCol, cCaption, lGroup, lChecked, nPos, oWnd, oRadMenu,;
            nHelpId ) CLASS TRadio

   DEFAULT lChecked := .f., lGroup := .f., nPos := 1, nHelpId := 100

   ::nTop     = nRow * 13
   ::nLeft    = ( nCol *  7 ) + 4
   ::nBottom  = ::nTop + 12
   ::nRight   = ::nLeft + ( Len( cCaption ) * 5 )
   ::cCaption = cCaption
   ::nStyle   = nOR( WS_CHILD, WS_VISIBLE, BS_AUTORADIOBUTTON,;
                       If( lGroup, WS_GROUP, 0 ) )
   ::nId      = ::GetNewId()
   ::nHelpId  = nHelpId
   ::lChecked = lChecked
   ::nPos     = nPos
   ::oWnd     = oWnd
   ::oRadMenu = oRadMenu

   if oWnd:ClassName() != "TDIALOG"
      ::Create( "BUTTON" )
   else
      oWnd:DefControl( Self )
   endif

return

//---------------------------------------------------------------------------//

METHOD Redefine( nID, lChecked, nPos, oDlg, oRadMenu, nHelpID ) CLASS TRadio

   DEFAULT lChecked := .f., nPos := 1, nHelpId := 100

   ::nId      = nID
   ::nHelpId  = nHelpId
   ::oWnd     = oDlg
   ::oRadMenu = oRadMenu
   ::lChecked = lChecked
   ::nPos     = nPos

   oDlg:DefControl( Self )

return
//----------------------------------------------------------------------------//
